---@class WenheYanbing.AI: Base.AI
local AI = Fk.Base.AI:subclass("WenheYanbing.AI")

---@class WenheYanbing.AI
---@field public room WenheYanbing.Room
---@field public player WenheYanbing.ServerPlayer

function AI:initialize(player)
    Fk.Base.AI.initialize(self, player)
end

-- AI决策：简单的自动操作
function AI:makeDecision()
    local player = self.player
    
    -- 如果有足够的金币就升级酒馆
    if player:getUpgradeCost() <= player.gold then
        player:upgradeTavern()
    end
    
    -- 购买商店中的随从
    for i = #player.tavernMinions, 1, -1 do
        local minion = player.tavernMinions[i]
        if minion.cost <= player.gold then
            player:buyMinion(i)
            break
        end
    end
    
    -- 刷新商店（如果有金币且商店不好）
    if player.gold >= 1 and #player.tavernMinions > 0 then
        local shouldRefresh = math.random() < 0.3  -- 30%概率刷新
        if shouldRefresh then
            player:refreshTavern()
        end
    end
    
    -- 放置手牌中的随从到战场
    for i, minion in ipairs(player.hand) do
        if #player.board < 7 then
            player:placeMinion(i, #player.board + 1)
        end
    end
    
    -- 出售弱小的随从（如果有太多）
    if #player.board >= 6 then
        local weakestIndex = 1
        for i, minion in ipairs(player.board) do
            if minion.attack + minion.health < player.board[weakestIndex].attack + player.board[weakestIndex].health then
                weakestIndex = i
            end
        end
        player:sellMinion(weakestIndex)
    end
end

return AI